package com.chenyun.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author Lonni
 * @Description: 分页结果类
 * @date 2021/7/1616:47
 */
@Data

@AllArgsConstructor

public class PageResult {
    //是否成功
    private boolean success;
    //返回码
    private Integer code;
    //返回信息
    private String message;


    private long pageIndex;
    private long page;
    private long pageSize;
    private long total;
    //返回数据
    private Object data;

    public PageResult() {
        this.success = true;
        this.message = "操作成功";
        this.code = ResultCode.SUCCESS.code;
    }

    public PageResult(int total, Object data) {
        this.success = true;
        this.message = "操作成功";
        this.code = ResultCode.SUCCESS.code;
        this.total = total;
        this.data = data;
    }

    public static PageResult FAIL(String message) {
        PageResult result = new PageResult();
        result.setSuccess(false);
        result.setMessage(message);
        result.setCode(ResultCode.FAIL.code);
        return result;
    }

    public static PageResult FAIL(String message, Integer code) {
        PageResult fail = PageResult.FAIL(message);
        fail.setCode(code);
        return fail;
    }


}
